package com.ceshiren.chnjx.wework.page.message;

import com.ceshiren.chnjx.wework.page.BasePage;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;

/**
 * @author: JJJJ
 * @date:2021/11/3 17:24
 * @Description: TODO
 */
public class MessageManagerPage extends BasePage {


    private By selectApplicationBtn = new By.ByLinkText("选择需要发消息的应用");
    private By announcementBtn = new By.ByCssSelector("[data-name='公告']");
    private By confirmBtn = new By.ByLinkText("确定");
    private By SendingRangeBtn = new By.ByLinkText("选择发送范围");
    private By titleInput = new By.ByXPath("//*[@placeholder='在此输入标题']");
    private By contentInput = new By.ByXPath("//*[@contenteditable='true']");
    private By authorInput = new By.ByXPath("//*[@placeholder='请填写发布者']");;
    private By sendBtn = new By.ByLinkText("发送");
    private By confirmBtn2 = new By.ByLinkText("确认");
    private By contentFrame = new By.ByXPath("//*[@id='edui1_iframeholder']/iframe");
    private By sendListContentLoc = new By.ById("messageListContent");
    public MessageManagerPage(WebDriver driver) {
        super(driver);
    }

    /**
     * 发送公告
     * @param title 公告标题
     * @param announcementContent  公告内容
     * @param sendRange 发送范围
     * @param author 作者
     * @return
     */
    public MessageManagerPage sendAnnouncement(String title, String announcementContent, String sendRange, String author){
        clickElement(selectApplicationBtn);
        clickElement(announcementBtn);
        clickElement(confirmBtn);
        clickElement(SendingRangeBtn);
        clickElement(new By.ByLinkText(sendRange));
        clickElement(confirmBtn2);
        sendData(titleInput,title);
        // 切换frame
        switchToFrame(contentFrame);
        sendData(contentInput,announcementContent);
        switchToParentFrame();
        sendData(authorInput,author);
        clickElement(sendBtn);
        clickElement(confirmBtn);
        try {
            Thread.sleep(500);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return this;
    }

    /**
     * 获取已发送列表内容
     * @return
     */
    public String getSendListContent(){
        return getElementText(sendListContentLoc);
    }
}
